home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / tos / gnulib / libsrc98.zoo / device.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-24  |  1.4 KB  |  81 lines

  1. #include <device.h>
  2. #include <stddef.h>
  3. #include <string.h>
  4.  
  5. /*
  6.  * Pseudo-device interface stuff. New devices can be hooked into the chain
  7.  * that's rooted at __devices. All _unx2dos and low level i/o functions use this
  8.  * chain in determining whether files are devices or disk files, as does stat().
  9.  * The major device number of user-supplied devices must *NOT* be 0 or 0xff,
  10.  * both of which are reserved.
  11.  */
  12.  
  13. static struct _device prn_dev = {
  14. "PRN:", "lp", 0xfffd, NULL, NULL, NULL, NULL, NULL, 0
  15. };
  16.  
  17. static struct _device aux_dev = {
  18. "AUX:", "tty1", 0xfffe, NULL, NULL, NULL, NULL, NULL, &prn_dev
  19. };
  20.  
  21. static struct _device con_dev = {
  22. "CON:", "console", 0xffff, NULL, NULL, NULL, NULL, NULL, &aux_dev
  23. };
  24.  
  25. struct _device *__devices = &con_dev;
  26.  
  27. /*
  28.  * install a new device
  29.  */
  30.  
  31. void
  32. _install_device(d)
  33.     struct _device *d;
  34. {
  35.     d->next = __devices;
  36.     __devices = d;
  37. }
  38.  
  39. /*
  40.  * find a device based on it's file descriptor
  41.  */
  42.  
  43. struct _device *
  44. _dev_fd(fd)
  45.     int fd;
  46. {
  47.     struct _device *d;
  48.  
  49.     for (d = __devices; d; d = d->next)
  50.         if (d->dev == fd) break;
  51.     return d;
  52. }
  53.  
  54. /*
  55.  * find a device based on its DOS or UNIX name.
  56.  */
  57.  
  58. struct _device *
  59. _dev_dosname(dosnm)
  60.     const char *dosnm;
  61. {
  62.     struct _device *d;
  63.  
  64.     for (d = __devices; d; d = d->next) {
  65.         if (!strcmp(dosnm, d->dosnm)) break;
  66.     }
  67.     return d;
  68. }
  69.  
  70. struct _device *
  71. _dev_unxname(unm)
  72.     const char *unm;
  73. {
  74.     struct _device *d;
  75.  
  76.     for (d = __devices; d; d = d->next) {
  77.         if (!strcmp(unm, d->unxnm)) break;
  78.     }
  79.     return d;
  80. }
  81.